<?php

namespace App\Http\Controllers;

use App\Models\Products;
use Illuminate\Http\Request;

class SearchController extends Controller
{
    public function searchProducts(Request $request){
        //获取用户输入的搜索关键字
        $search = $request->input('search');

        $searchRes = Products::where('name','like','%'.$search.'%')
            ->orWhere('summary','like','%'.$search.'%')
            ->get();

        //将查询结果传递给查询后的商品列表页面
        return view('searchpage',['searchRes'=>$searchRes]);
    }
}
